package com.william.jdbcplus.boot.starter.service.impl;

import com.william.jdbcplus.boot.starter.service.IService;
import com.william.jdbcplus.common.entity.Entity;
import com.william.jdbcplus.common.page.IPage;
import com.william.jdbcplus.core.dao.IBaseDao;
import com.william.jdbcplus.core.query.EntityWrap;
import com.william.jdbcplus.core.query.UpdateWrap;
import lombok.AllArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @author niliwei
 */
@AllArgsConstructor
public class ServiceImpl implements IService {

    private IBaseDao dao;

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> String add(M entity) {
        return dao.add(entity);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean addOrUpdate(M entity) {
        return dao.addOrUpdate(entity);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean addOrUpdateList(Collection<M> entityList) {
        return dao.addOrUpdateList(entityList);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean copyList(List<M> entityList) {
        return dao.copyList(entityList);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean addList(List<M> entityList) {
        return dao.addList(entityList);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean updateById(String id, UpdateWrap<M> updateWrap) {
        return dao.updateById(id, updateWrap);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean updateById(M entity) {
        return dao.updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean update(M entity, EntityWrap<M> wrap) {
        return dao.update(entity, wrap);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean update(UpdateWrap<M> updateWrap, EntityWrap<M> entityWrap) {
        return dao.update(updateWrap, entityWrap);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean updateByMap(Map<String, Object> columnMap, EntityWrap<M> wrap) {
        return dao.updateByMap(columnMap, wrap);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean updateList(Collection<M> entityList) {
        return dao.updateList(entityList);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean updateAll(M entity) {
        return dao.updateAll(entity);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean deleteById(String id, Class<M> entityClass) {
        return dao.deleteById(id, entityClass);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean deleteByIds(Collection<String> ids, Class<M> entityClass) {
        return dao.deleteByIds(ids, entityClass);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean delete(EntityWrap<M> wrap) {
        return dao.delete(wrap);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean deleteAll(Class<M> entityClass) {
        return dao.deleteAll(entityClass);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean realDelById(String id, Class<M> entityClass) {
        return dao.realDelById(id, entityClass);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean realDelByIds(Collection<String> ids, Class<M> entityClass) {
        return dao.realDelByIds(ids, entityClass);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean realDel(EntityWrap<M> wrap) {
        return dao.realDel(wrap);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public <M extends Entity> boolean realDelAll(Class<M> entityClass) {
        return dao.realDelAll(entityClass);
    }

    @Override
    public <M extends Entity> M getById(String id, Class<M> entityClass) {
        return dao.getById(id, entityClass);
    }

    @Override
    public <M extends Entity> M get(EntityWrap<M> wrap) {
        return dao.get(wrap);
    }

    @Override
    public <M extends Entity> boolean exists(String id, Class<M> entityClass) {
        return dao.exists(id, entityClass);
    }

    @Override
    public <M extends Entity> boolean exists(EntityWrap<M> wrap) {
        return dao.exists(wrap);
    }

    @Override
    public <M extends Entity> int countAll(Class<M> entityClass) {
        return dao.countAll(entityClass);
    }

    @Override
    public <M extends Entity> int count(EntityWrap<M> wrap) {
        return dao.count(wrap);
    }

    @Override
    public <M extends Entity> List<M> listAll(Class<M> entityClass) {
        return dao.listAll(entityClass);
    }

    @Override
    public <M extends Entity> List<M> list(EntityWrap<M> wrap) {
        return dao.list(wrap);
    }

    @Override
    public <M extends Entity> List<M> listByIds(Collection<?> idList, Class<M> entityClass) {
        return dao.listByIds(idList, entityClass);
    }

    @Override
    public <M extends Entity> IPage<M> page(IPage<?> page, EntityWrap<M> wrap) {
        return dao.page(page, wrap);
    }
}
